// oplog.go
package models_mongo

import (
	"github.com/satori/go.uuid"
	"time"
	"martini_template/componnet"
)

var lCollection = "op_log"

type OpLog struct {
	Id         string `bson:"id"`
	CreateTime int64  `bson:"create_time"`
	OpTime     int64  `bson:"op_time"`
	OperId     string `bson:"oper_id"`
	OpAction   string `bson:"op_action"`
	OpType     string `bson:"op_type"`
	OpIP       string `bson:"op_ip"`
	OpContent  string `bson:"op_content"`
}

func (model *OpLog) SaveLog() bool {
	model.Id = uuid.NewV4().String()
	model.CreateTime = time.Now().Unix()
	insertErr := mongoDb.C(lCollection).Insert(model)
	if insertErr == nil {
		return true
	} else {
		componnet.Elogger.Println(insertErr)
		return false
	}
}
